package com.ajx.blog.service.impl;

import com.ajx.blog.entity.Blogusers;
import com.ajx.blog.mapper.BlogusersMapper;
import com.ajx.blog.service.api.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {
    private Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private BlogusersMapper blogusersMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int addUser(Blogusers blogusers) {
        logger.info("调用了添加用户的业务");
        return blogusersMapper.insert(blogusers);
    }

    @Override
    public Blogusers userLogin(String s) {
        logger.info("调用了用户登录的业务");
        QueryWrapper<Blogusers> adminQueryWrapper = new QueryWrapper<>();
        adminQueryWrapper.eq("uphone", s).or().eq("uemail", s);
        return blogusersMapper.selectOne(adminQueryWrapper);
    }

    @Override
    public Blogusers userLoginByName(String name) {
        logger.info("根据用户名获取用户信息");
        QueryWrapper<Blogusers> adminQueryWrapper = new QueryWrapper<>();
        adminQueryWrapper.eq("uname", name);
        return blogusersMapper.selectOne(adminQueryWrapper);
    }

}
